package aivin.android_jni_cpp;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import aivin.android_jni_cpp.bean.Car;
import aivin.android_jni_cpp.jniTool.MyJniTools;

public class MainActivity extends AppCompatActivity
{
    static
    {
        System.loadLibrary("AivinNative-lib");
    }
    public   native String checkPackageNameIsLegal( ) ;
    public native int checkApkSingLegalByHashCode() ;


    TextView resultTxt ;
    Activity mActivity ;
    Context mCtx ;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mActivity = this ;
        mCtx= this;


        resultTxt = (TextView) findViewById(R.id.resultTxt);
        findViewById(R.id.bt0).setOnClickListener(onClickListener);
        findViewById(R.id.bt1).setOnClickListener(onClickListener);
        findViewById(R.id.bt2).setOnClickListener(onClickListener);
        findViewById(R.id.bt3).setOnClickListener(onClickListener);
        findViewById(R.id.bt4).setOnClickListener(onClickListener);
        findViewById(R.id.bt5).setOnClickListener(onClickListener);
        findViewById(R.id.bt6).setOnClickListener(onClickListener);
        findViewById(R.id.bt7).setOnClickListener(onClickListener);
        findViewById(R.id.bt10).setOnClickListener(onClickListener);
        findViewById(R.id.bt11).setOnClickListener(onClickListener);



    }




    private View.OnClickListener onClickListener = new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            switch (v.getId())
            {
                case R.id.bt0:
                    break;
                case R.id.bt1:
                    resultTxt.setText(MyJniTools.userLogin("aivin" ,"1234"));
                    break;
                case R.id.bt2:
                    resultTxt.setText(""+MyJniTools.goToNative(10));
                    break;
                case R.id.bt3:
                    MyJniTools.getJavaFile() ;
                    resultTxt.setText(MyJniTools.rootName);
                    break;

                case R.id.bt4:

                    MyJniTools myJniTools = new MyJniTools(mActivity) ;
                    myJniTools.startShowProgress(/*resultTxt ,*/);
                    break;

                case R.id.bt5:
                    MyJniTools myJniTools1 = new MyJniTools(mActivity) ;
                    byte[] bytes ={3 , 4 , 5 } ;
                    byte[] result = myJniTools1.processArray(bytes) ;
                    StringBuilder sb = new StringBuilder() ;
                    for(byte b: result)
                    {
                        sb.append( b) ;
                        sb.append("   ") ;
                    }

                    resultTxt.setText("修改后的数据=" +sb.toString());
                    break;

                case R.id.bt6:
                    MyJniTools tools6 = new MyJniTools(mActivity) ;
                    Car car = tools6.getCarWithArgs("奔驰"  , 300000);
                    resultTxt.setText("car=" +car.getCarType()+"  "+car.getPrice());
                    break;


                case R.id.bt7:
                    break;
                case R.id.bt10:
//                    MyJniTools tools10 = new MyJniTools(mActivity) ;
                    String reslut =checkPackageNameIsLegal();
                    resultTxt.setText("包名="+reslut);
                    break;
                case R.id.bt11:

                    int reslut11 = checkApkSingLegalByHashCode();
                    int hashCode = MyJniTools.getApkHashCodeByJava(mCtx) ;
                    resultTxt.setText(" 签名的hashcode :   jni获取的 = " + reslut11 +"    java获取的="+ hashCode);
                    break;
            }

        }
    } ;



    private void tostMsg(String msg)
    {
        Toast.makeText(this ,msg , Toast.LENGTH_SHORT).show();
    }

}
